package com.hmall.common.config;



import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
// 判断RabbitTemplate类是否存在 --> 条件注解,满足是才会加载
//如果类架子器中有rabbitTemplate类时,才会加载该配置类
@ConditionalOnClass(RabbitTemplate.class)
public class MQConfig {
    // 使用的是amqp
    // 注册json消息转换器
    @Bean
    public MessageConverter messageConverter(){
        Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
        //设置每个消息动携带一个id
        converter.setCreateMessageIds(true);
        return converter;
    }
}
